<?php
namespace Admin\Controller;

/**
 * 后台管理商品管理控制器
 * @author RickChan
 */
class CustomerController extends AdminController {
	public function index(){
		$list = $this->lists('Customer',array('status!=-1'),'id desc');
		int_to_string($list);
		$this->assign('_list', $list);
		$this->meta_title = '客户管理';
		$this->display();
	}

	public function edit(){
		$id = I('get.id');
		empty($id) && $this->error('参数不能为空！');
		$data = M('Customer')->field(true)->find($id);
		$this->assign('data',$data);
		$this->meta_title = '编辑客户';
		$this->display('editcustomer');
	}

	public function createCustomer(){
		$this->assign('data',null);
		$this->meta_title = '新增客户';
		$this->display('editcustomer');
	}

	public function writeCustomer(){
		$res = D('Customer')->update();
		if(!$res){
		    $this->error(D('Customer')->getError());
        }else{
            $this->success($res['id']?'更新成功！':'新增成功！', U('index'));
        }
	}

	public function changeStatus($method=null){
		$id = array_unique((array)I('id',0));
		$id = is_array($id) ? implode(',', $id) : $id;
		if (empty($id)){
			$this->error('请选择要操作的数据！');
		}
		$map['id'] = array('in',$id);
		switch (strtolower($method)) {
			case 'forbidcustomer':
                $this->forbid('Customer', $map );
                break;
            case 'resumecustomer':
                $this->resume('Customer', $map );
                break;
            case 'deletecustomer':
                $this->delete('Customer', $map );
                break;
            default:
                $this->error('参数非法');
				break;
		}
	}
}